@isTest
private class SalesPerformanceDataSheetControllerTest {
    static testMethod void testMethod1() {


    	Id ldcProfile = [Select Id From Profile Where Name like '%工程师%' limit  1  ].Id;

         User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         CompanyName= 'Y-MKSY',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         Province__c = '四川省',
                         Username = 'Matldc1@test.com.maike',
                         FederationIdentifier ='123451', 
                         ManagerId= UserInfo.getUserId(),
                         ResponseCode__c = 'TTTT' );
         insert u1;

        Id ReagentPerformance = Utils.getRecordTypeIdByDevNameAndObjName('ReagentPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c regent = new SalesPerformanceDataSheet__c(
    			RecordTypeId = ReagentPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '123451',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			ActualSales__c = 10000,
    			ActualSalesQ1__c = 2500,
    			ActualSalesQ2__c = 2500,
    			ActualSalesQ3__c = 2500,
    			ActualSalesQ4__c = 2500,

    			BudgetSales__c = 10000,
    			BudgetSalesQ1__c = 2500,
    			BudgetSalesQ2__c = 2500,
    			BudgetSalesQ3__c = 2500,
    			BudgetSalesQ4__c = 2500,

				LastYearSalesVolume__c = 8000,
				LastYearSalesVolumeQ1__c = 2000,
				LastYearSalesVolumeQ2__c = 2000,
				LastYearSalesVolumeQ3__c = 2000,
				LastYearSalesVolumeQ4__c = 2000

    		);


        Id ReagentPerformanceSum = Utils.getRecordTypeIdByDevNameAndObjName('ReagentPerformanceSum', 'SalesPerformanceDataSheet__c');

        SalesPerformanceDataSheet__c regentSum = new SalesPerformanceDataSheet__c(
                RecordTypeId = ReagentPerformanceSum,
                Year__c = System.today().year()+'年',
                
                Quarter__c = '1',
                Company__c = 'MKSW',
                EmployeeNumber__c = '123451',
                Name__c = '测试',
                JobCategory__c = '直销销售员',
                SalesMarket__c = '经销商',
                ReagentCategory__c = '迈克试剂',
                ActualSales__c = 10000,
                ActualSalesQ1__c = 2500,
                ActualSalesQ2__c = 2500,
                ActualSalesQ3__c = 2500,
                ActualSalesQ4__c = 2500,

                BudgetSales__c = 10000,
                BudgetSalesQ1__c = 2500,
                BudgetSalesQ2__c = 2500,
                BudgetSalesQ3__c = 2500,
                BudgetSalesQ4__c = 2500,

                LastYearSalesVolume__c = 8000,
                LastYearSalesVolumeQ1__c = 2000,
                LastYearSalesVolumeQ2__c = 2000,
                LastYearSalesVolumeQ3__c = 2000,
                LastYearSalesVolumeQ4__c = 2000

            );



    	Id InstrumentPerformance = Utils.getRecordTypeIdByDevNameAndObjName('InstrumentPerformance', 'SalesPerformanceDataSheet__c');
    	SalesPerformanceDataSheet__c equip = new SalesPerformanceDataSheet__c(
    			RecordTypeId = InstrumentPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '123451',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			InstrumentClasses__c = 'C800',
    			ActualQuantity__c = 100,
    			ActualQuantityQ1__c = 25,
    			ActualQuantityQ2__c = 25,
    			ActualQuantityQ3__c = 25,
    			ActualQuantityQ4__c = 25,

    			BudgetQuantity__c = 100,
    			BudgetQuantityQ1__c = 25,
    			BudgetQuantityQ2__c = 25,
    			BudgetQuantityQ3__c = 25,
    			BudgetQuantityQ4__c = 25


    		);
    	
    	Id ReagentIncrementalPerformance = Utils.getRecordTypeIdByDevNameAndObjName('ReagentIncrementalPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c regent_increase = new SalesPerformanceDataSheet__c(
    			RecordTypeId = ReagentIncrementalPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '123451',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			Category__c = '特殊项目',
    			ActualSales__c = 10000,
    			ActualSalesQ1__c = 2500,
    			ActualSalesQ2__c = 2500,
    			ActualSalesQ3__c = 2500,
    			ActualSalesQ4__c = 2500,

    			
				LastYearSalesVolume__c = 8000,
				LastYearSalesVolumeQ1__c = 2000,
				LastYearSalesVolumeQ2__c = 2000,
				LastYearSalesVolumeQ3__c = 2000,
				LastYearSalesVolumeQ4__c = 2000
    		);

    	Id AnnualIncrementPerformance = Utils.getRecordTypeIdByDevNameAndObjName('AnnualIncrementPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c regent_annual_increase = new SalesPerformanceDataSheet__c(
    			RecordTypeId = AnnualIncrementPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '123451',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			ActualSales__c = 10000,
    			BudgetSales__c = 10000,

				LastYearSalesVolume__c = 8000
				

    		);
    	Id AgentIncrementPerformance = Utils.getRecordTypeIdByDevNameAndObjName('AgentIncrementPerformance', 'SalesPerformanceDataSheet__c');

    	SalesPerformanceDataSheet__c agent_annual_increase = new SalesPerformanceDataSheet__c(
    			RecordTypeId = AgentIncrementPerformance,
    			Year__c = System.today().year()+'年',
    			
    			Quarter__c = '1',
    			Company__c = 'MKSW',
    			EmployeeNumber__c = '123451',
    			Name__c = '测试',
    			JobCategory__c = '直销销售员',
    			SalesMarket__c = '经销商',
    			ReagentCategory__c = '迈克试剂',
    			ActualSales__c = 10000,
    		
    			BudgetSales__c = 10000,

				LastYearSalesVolume__c = 8000
				

    		);

    	insert new List<SalesPerformanceDataSheet__c>{regent,regentSum,regent_annual_increase,agent_annual_increase ,equip ,regent_increase };
    	

    	SalesPerformanceAdjustment__c sa = new SalesPerformanceAdjustment__c();
    	sa.Quarter__c = '1';
    	sa.Year__c = '2020年';
    	sa.CompanyName__c = '四川省迈克实业有限公司';

    	insert sa;


    	PageReference page2 = new PageReference('/apex/SalesPerformanceDataSheet?id='+sa.Id);
        System.Test.setCurrentPage(page2);
    	SalesPerformanceDataSheetController str  = new SalesPerformanceDataSheetController();


    	str.initDetails();
    	Map<String,String> searchMap = new Map<String,String>();
    	searchMap.put('rtype', 'ReagentPerformance');
    	searchMap.put('workno',u1.Id  );
    	
    	searchMap.put('quater','1'  );
    	searchMap.put('year','2020年' );

    	str.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');


    	str.searchDetail();

    	str.init();
    	str.search();

    	List<Object> saveList = new List<Object>();
    	SalesPerformanceDataSheetController.PerformanceBean spb = new SalesPerformanceDataSheetController.PerformanceBean(regent);

    	spb.as2 = 100;
    	
    	saveList.add(spb);

    	Map<String,Object> saveMap = new Map<String,Object>();

    	Map<String,Object> adMap = new Map<String,Object>();
    	adMap.put('ReagentPerformanceAdjust', saveList);
    	saveMap.put('details',adMap);

    	Map<String,String>baseMap = new Map<String,String>();
    	baseMap.put('User__c',u1.Id);

    	saveMap.put('base',baseMap);

    	str.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap), 'UTF-8');

    	str.save();

    	sa.Status__c = '审批成功';
    	update sa;


    }


}